<template>
  <view class="form-group">
    <view class="phone-div">
      <!-- #ifndef APP-NVUE -->
      <u-input placeholder="请输入当前密码" v-model='password'>
        <!-- #endif -->
        <!-- #ifdef APP-NVUE -->
        <u--input placeholder="请输入当前密码" v-model='password'>
          <!-- #endif -->
          <u--text text="当前密码" slot="prefix" margin="0 3px 0 0" type="tips"></u--text>
          <!-- #ifndef APP-NVUE -->
      </u-input>
      <!-- #endif -->
      <!-- #ifdef APP-NVUE -->
      </u--input>
      <!-- #endif -->
    </view>
    <view class="phone-div">
      <!-- #ifndef APP-NVUE -->
      <u-input placeholder="请输入新密码" :password="true" v-model='newPassword'>
        <!-- #endif -->
        <!-- #ifdef APP-NVUE -->
        <u--input placeholder="请输入新密码" :password="true" v-model='newPassword'>
          <!-- #endif -->
          <u--text text="新的密码" slot="prefix" margin="0 3px 0 0" type="tips"></u--text>
          <!-- #ifndef APP-NVUE -->
      </u-input>
      <!-- #endif -->
      <!-- #ifdef APP-NVUE -->
      </u--input>
      <!-- #endif -->
    </view>
    <view class="phone-div">
      <!-- #ifndef APP-NVUE -->
      <u-input placeholder="请输入新密码" :password="true" v-model='truePassword'>
        <!-- #endif -->
        <!-- #ifdef APP-NVUE -->
        <u--input placeholder="请输入新密码" :password="true" v-model='truePassword'>
          <!-- #endif -->
          <u--text text="确认密码" slot="prefix" margin="0 3px 0 0" type="tips"></u--text>
          <!-- #ifndef APP-NVUE -->
      </u-input>
      <!-- #endif -->
      <!-- #ifdef APP-NVUE -->
      </u--input>
      <!-- #endif -->
    </view>
    <view class="phone-div">
      <u-button type="primary" text="确认" @click="confirm"></u-button>
    </view>
    <view class="phone-div">
      <text class="tips">更换密码后，下次登录可使用新密码登录</text>
    </view>
		<u-modal :show="isConfirm" content="你确定要修改密码吗?" :closeOnClickOverlay="true" :showCancelButton="true"
			@cancel="isConfirm=false" @close="isConfirm=false" @confirm="resetPsd">
		</u-modal>
		<u-toast ref="uToast"></u-toast>
  </view>
</template>

<script>
	import {reset_psd} from '@/api/contents/user/user.js'
	import md5 from 'md5-node'
  export default {
    data() {
      return {
				password:'',//当前密码
				newPassword:'',//新密码
				truePassword:'',//确认新密码
				isConfirm:false,
      };
    },
		methods:{
			confirm(){
				if(this.newPassword!==this.truePassword){
					uni.showToast({
						title:'两次输入密码不一致,请重新输入！',
						icon:'none'
					})
					this.password=''
					this.newPassword=''
					this.truePassword=''
					return ;
				}
				this.isConfirm=true;
			},
			resetPsd(){
				reset_psd({
					password:md5(this.password),
					confirmPsd:md5(this.newPassword)
				}).then(res=>{
					this.isConfirm=false;
					if(res.code==1){
						this.$refs.uToast.show({
							message: '修改密码成功！',
							complete() {
								uni.navigateBack();
							}
						})
					}else{
						uni.showToast({
							title:'您输入的密码错误！',
							icon:'none'
						})
					}
				})
			}
			
		}
  }
</script>

<style lang="scss" scoped>
  .form-group{
    padding: 30upx 80upx;
  }
  .phone-div {
    padding-bottom: 20upx;
    text-align: center;

    .tips {
      font-size: 20upx;
      font-weight: 400;
      color: #547bff;
      letter-spacing: 0.1px;
    }
  }
</style>
